package com.example.mapper;

import com.example.pojo.Event;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EventMapper {
    @Select("select * from event where eventID = #{eventID}")
    Event getByID(Integer eventID);

    void deleteByIDs(List<Integer> eventIDs);

    @Insert("insert into event(userID,event_name,start_time,end_time," +
            "low_price,mid_price,high_price,image,event_descr,place," +
            "on_sale,create_time,update_time)" +
            "values(#{userID},#{eventName},#{startTime},#{endTime}," +
            "#{lowPrice},#{midPrice},#{highPrice},#{image}," +
            "#{eventDescr},#{place},#{onSale},#{createTime},#{updateTime})")
    //将新增数据的主键值返还给event的eventID字段
    @Options(useGeneratedKeys = true,keyProperty = "eventID")
    void save(Event event);


    void update(Event event);

    List<Event> list(String eventName, Short place, Short onSale, Integer userID, LocalDate begin, LocalDate end, Integer startIdx, Integer pageSize);
    long listCount(String eventName, Short place, Short onSale, Integer userID, LocalDate begin, LocalDate end, Integer startIdx, Integer pageSize);

    @Update("update event set on_sale = #{i} where eventID = #{eventID}")
    void changeSale(Integer eventID, Integer i);
}
